<template>
  <el-dialog :visible.sync="taxClassVisible" width="90%" :title="dialogTitle"   :modal='false'   >

    <!--搜索框-->
    <el-form
        :inline="true"
        :model="searchParams"
        style="width: 100%"
        size="small"
        class="formInline"
    >
      <el-form-item
          label="商品和服务税收分类合并编码"
      >
        <el-input
            style="width: 200px"
            v-model="searchParams.input1"
            placeholder="请输入"
        ></el-input>
      </el-form-item>
      <el-form-item label="商品和服务名称"           >
        <el-input
            style="max-width: 160px"
            v-model="searchParams.input2"
            placeholder="请输入"
        ></el-input>
      </el-form-item>
      <el-form-item label="商品和服务分类简称" >
        <el-input
            style="width: 160px"
            v-model="searchParams.input3"
            placeholder="请输入"
        ></el-input>
      </el-form-item>

      <el-form-item >
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button type="primary" @click="onResize">重置</el-button>
        <el-button type="primary" @click="confirm">确定</el-button>
      </el-form-item>
    </el-form>
    <!--表格-->
    <tableList
        :showIndex="true"
        :loading="loading"
        border
        :heightMin="130"
        :pageNumber="pages.current"
        :pageSize="pages.size"
        :total="pages.total"
        :keySet="keySet"
        :autoHeight="true"
        :tableData="listDetails"
        :paginationShow="true"
        :handlerShow="true"
        @handleSizeChange="handleSizeChange"
        @handleCurrentChange="handleCurrentChange"
        :radioSelect="true"
        @radioHandleCurrentChange="radioHandleCurrentChange"

    >

    </tableList>
  </el-dialog>
</template>

<script>
import DictSelect from "@/views/invoiceTemplate/components/DictSelect/DictSelect.vue";
import {DictCode} from "@/utils/DictConstant";
import tableList from "@/components/tableList/index.vue";
import mixinTable from "@/mixin/mtable";

import {queryCodePage} from "@/api/serviceInformationManage";

export default {
  computed: {
    DictCode() {
      return DictCode
    }
  },

  components: { tableList, DictSelect},
  mixins: [mixinTable],
  props: {
    dialogTitle: {
      type: String,
      default: '税收分类'
    }
  },
  data() {
    return {
      taxClassVisible: false,
      loading: false,
      keySet: [
        {
          label: '父级编码',
          englishName: 'fjbm',
          width: 70
        },
        {
          label: '商品和服务税收分类合并编码',
          englishName: 'sphfwssflhbbm',
          width: 180,
          align: 'center',
        },
        {
          label: '特定要素标签归类',
          englishName: 'tdyslxdm',
          width: 120,
          align: 'center',
        },
        {
          label: '差额征税',
          englishName: 'cezs',
          width: 70,
        },
        {
          label: '不征税',
          englishName: 'bzs',
          width: 60,
        },
        {
          label: '即征即退代码集合',
          englishName: 'jzjtdm',
          width: 160,
          align: 'center',
        },
        {
          label: '商品和服务名称',
          englishName: 'sphfwmc',
          width: 130,
          align: 'center',
        },
        {
          label: '商品和服务分类简称',
          englishName: 'sphfwfljc',
          width: 130,
          align: 'center',
        },
        {
          label: '说明',
          englishName: 'sm',
          width: 70,
        },
        {
          label: '增值税税率',
          englishName: 'zzssl',
          width: 90,
        },
        {
          label: '征收率',
          englishName: 'zsl',
          width: 80,
        },
        {
          label: '增值税特殊管理',
          englishName: 'zzstsgl',
          width: 110,
        },
        {
          label: '增值税政策依据',
          englishName: 'zzszcyj',
          width: 110,
        },
        {
          label: '增值税特殊内容代码',
          // '（增值税减免税政策代码表）',
          englishName: 'zzstsnrdm',
          width: 130,
          align: 'center',
        },
        {
          label: '消费税管理',
          englishName: 'xfsgl',
          width: 90,
        },
        {
          label: '消费税政策依据',
          englishName: 'xfszcyj',
          width: 110,
          align: 'center',
        },
        {
          label: '消费税特殊内容代码',
          englishName: 'xfstsnrdm',
          width: 130,
          align: 'center',
        },
        {
          label: '关键字',
          englishName: 'gjz',
          width: 70,
        },
        {
          label: '是否汇总项',
          englishName: 'sfhzx',
          width: 90,
        },
        {
          label: '对应统计局编码（2011年版）或国民行业代码',
          englishName: 'dytjjbm',
          width: 'labelWidth',
          align: 'center',
        },
        {
          label: '海关进出口商品品目',
          englishName: 'hgjcksppm',
          width: 130,
          align: 'center',
        },
        {
          label: '启用日期',
          englishName: 'qyrq',
          width: 80,
        },
        {
          label: '停用日期',
          englishName: 'tyrq',
          width: 80,
        },

      ],
      application: '',//应用范围
      jyjgArr: '',//机构id集合
      listDetails: [],
      selectRow: null
    };
  },
  mounted() {

  },
  created() {
    this.getList()
  },
  methods: {
    onSubmit() {
      this.getList()
    },
    onResize() {
      this.onResizeFn()
      this.getList()
    },
    // 查询.根据机构查询数据
    async getList() {
      this.loading = true
      let {data, code, message} = await queryCodePage(
          {
            sphfwssflhbbm: this.searchParams.input1,
            sphfwmc: this.searchParams.input2,
            sphfwfljc: this.searchParams.input3,
            jyjgArr: this.jyjgArr,//机构id集合 TODO 后端根据拼接好的机构ID集合和应用范围两个参数，来联合查询能够选择的数据
            application: this.application,//应用范围
            pageNo: this.pages.current,
            pageSize: this.pages.size,
          }
      )
      if (code == 200) {
        this.loading = false
        this.listDetails = data.records
        this.time = data.records[0]?.createTime

        this.pages.total = data.total
        this.pages.current = data.current
        this.pages.size = data.size

      } else {
        this.$message({
          type: 'success',
          message: message,
        })
      }
      this.loading = false
    },
    open(params) {
      //TODO 将机构按照逗号拼接 并赋值到查询条件中
      this.jyjgArr=params.jyjg;
      this.application = params.application;
      this.getList()
    },
    // 单选
    radioHandleCurrentChange(val) {
      this.selectRow = val
    },
    //确定按钮
    confirm() {
      //选择一行数据
      //console.log(this.selectRow)
      //将对应的字段值赋值给父组件
      this.$emit('getTaxClass', this.selectRow)
      this.clearSearchInfo()
      //关闭弹窗
      this.taxClassVisible = false
    },
    // 关闭弹窗后，清空数据，再次进来，根据机构查询数据
    clearSearchInfo(){
      this.searchParams={
        input1: '',
        input2: '',
        input3: '',

      }
      // 清空查询条件,可能会包括机构的合集
      this.jyjgArr = []
      this.application = ''
    }
  },
};
</script>

<style scoped>

</style>